

<include file="public@header" />
</head>
<body>
<div class="wrap js-check-wrap">
    <ul class="nav nav-tabs">
        <li class="active"><a>兑换记录</a></li>

    </ul>

    <form class="well form-inline margin-top-20" method="get" >

        用户名:
        <input type="text" class="form-control" id="uname" style="width: 120px;"  placeholder="请输入用户名">

        券名称:
        <input type="text" class="form-control" id="tname" style="width: 120px;"  placeholder="请输入用户名">


        <input type="button" id="selectval" class="btn btn-primary" value="搜索" />
        <a class="btn btn-danger" href="{:url('ticketlogs/index')}">清空</a>
    </form>

    <table class="table table-hover table-bordered">

        <table class="layui-hide" id="test" lay-filter="test"></table>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
<!--                <button class="layui-btn layui-btn-sm " id="allscore"></button>-->
            </div>
        </script>
        <script type="text/html" id="barDemo">
<!--            <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
            <a class="layui-btn layui-btn-xs layui-btn-success"  lay-event="seelog">明细</a>
        </script>

        <script type="text/html" id="titleTpl">
            {{#  if(d.status == 0){ }}未使用 {{#  } }}
            {{#  if(d.status == 1){ }} 已使用{{#  } }}
            {{#  if(d.status == 2){ }} 已赠送{{#  } }}
            {{#  if(d.status == 3){ }} 已过期{{#  } }}
        </script>
        <!--1=赠送,2=后台,0=兑换',-->
        <script type="text/html" id="titleTpl1">
            {{#  if(d.get == 0){ }}用户兑换 {{#  } }}
            {{#  if(d.get == 1){ }} 用户赠送{{#  } }}
            {{#  if(d.get == 2){ }} 后台赠送{{#  } }}
        </script>

        <script>


            var url="{:url('ticketlogs/seelogs')}";

            layui.use('table', function(){
                var table = layui.table;


                var tableIns =table.render({
                    elem: '#test' ,
                    url:'index',
                    method: 'post',
                    toolbar: '#toolbarDemo',
                    title: '用户数据表',
                    totalRow: true ,
                    cols: [[
                        {field:'id', title:'ID', width:80, fixed: 'left', totalRowText: '合计'}
                        ,{field:'user_nickname', title:'用户',edit: 'text'}
                        ,{field:'name', title:'名称',edit: 'text'}
                        ,{field:'count', title:'数量', totalRow: true,sort: true}
                        ,{field:'gettime', title:'获得时间'}
                        ,{fixed: 'right', title:'操作', toolbar: '#barDemo'}
                    ]]
                    ,page: true,
                    done: function(res, curr, count){
                        console.log(res);
                        $("#allscore").html('合计持有:'+res.msg)
                    }
                });


                $("#selectval").click(function (){

                    var uname=$("#uname").val();
                    var fname=$("#fname").val();
                    var tname=$("#tname").val();
                    var status=$("#status").val();
                    var get=$("#get").val();


                    tableIns.reload({
                        where: { status: status,uname:uname,tname:tname,gets:get,fname:fname} ,
                        page: { curr: 1  }
                    });

                })

                //表格工具行事件
                table.on('tool(test)', function(obj){
                    var data = obj.data;
                    //console.log(obj)
                    if(obj.event === 'del'){
                        layer.confirm('真的删除么', function(index){

                            $.ajax({
                                url:'delete',
                                data:{'id':data.id},
                                type:'post',
                                success:function (ret){

                                    layer.msg(ret.msg)
                                    obj.del();
                                    layer.close(index);
                                }
                            })




                        });
                    }

                    if (obj.event=='seelog'){

                        var id=data.id;


                        var index=layer.open({
                            type: 2,
                            title:'参与信息',
                            area: ['1200px', '600px'],
                            content: url+'?id='+id,
                            success:function (){
                                // var index = parent.layer.getFrameIndex(window.name);
                                // parent.layer.close(index);
                            },
                            end: function() {
                                // console.log('关闭页面');
                                // location.reload();
                            },
                        });



                    }
                });




            });
        </script>


    </table>

</div>
<script src="__STATIC__/js/admin.js"></script>
</body>
</html>